<?php include('header.php'); ?>
<script type="text/javascript">
    function addCampaign() {
        window.location.href = "<?php echo $base_url; ?>campaign/form/";
    }
</script>
    <!-- Right Side/Main Content Start -->
    <div id="rightside">
        <table class="panel" >
            <tr>
                <td style="padding: 0;">
                    <!-- Alternative Content Box Start -->
                     <div class="contentcontainer">
                        <div class="headings altheading">
                            <h2>Your Campaigns</h2>
                        </div>
                        <div class="contentbox">
                            <table width="100%" class="grid">
                                    <thead>
                                    <tr>
                                        <th width="60px">Code</th>
                                        <th>Information</th>
                                        <th width="135px">Progress</th>
                                        <th width="100px">Status</th>
                                        <th width="100px">Actions</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php if ($campaign->countRows() > 0) { ?>
                                    <?php while ($campaign->fetchNext()) { ?>
                                    <tr>
                                        <td><?php echo $campaign->id; ?></td>
                                        <td>
                                            <h4><?php echo $campaign->name; ?></h4>
                                            <?php if ($campaign->description) { ?><p><i><?php echo $campaign->description; ?></i></p><?php } ?>
                                            <table width="100%" class="detail">
                                                <tr>
                                                    <td width="20%">Target :</td>
                                                    <td width="15%" style="text-align: right;"><?php echo $campaign->click_target; ?></td>
                                                    <td width="20%">&nbsp;</td>
                                                    <td width="20%">Likes :</td>
                                                    <td width="15%" style="text-align: right;"><?php echo $campaign->click_current; ?></td>
                                                    <td width="10%"></td>
                                                    <?php $percent = round(($campaign->click_current / $campaign->click_target) * 100, 2); ?>
                                                </tr>
                                                <tr>
                                                    <td colspan="6"><?php echo $campaign->url; ?></td>
                                                </tr>
                                                <tr>
                                                    <td colspan="6">
                                                        <?php $start = date_sql_to_timestamp($campaign->start_date); ?>
                                                        <?php if ($start > time()) { ?>
                                                        Will be started on&nbsp;:&nbsp;
                                                        <?php } else { ?>
                                                        Started on&nbsp;:&nbsp;
                                                        <?php } ?>
                                                        <?php 
                                                        echo strftime('%d/%m/%Y %H:%M',$start); 
                                                        ?>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                        <td>
                                            <div style="width:40px;float:right;text-align:center;margin-top:3px;" class="usagetxt <?php if ($percent <= 30) { ?>redtxt<?php } elseif ($percent <= 50 && $percent > 30) { ?>orangetxt<?php } else { ?>greentxt<?php } ?>" ><?php echo $percent.'%'; ?></div>
                                            <div style="width:70px;float:left;" class="usagebox"><div class="<?php 
                                        if ($percent <= 30) {
                                            echo 'highbar';
                                        }
                                        elseif ($percent <= 50 && $percent > 30) {
                                            echo 'midbar';
                                        }
                                        else {
                                            echo 'lowbar';
                                        }
                                                 ?>" style="width:<?php echo $percent; ?>%" >
                                            </div>
                                            </div>
                                        </td>
                                        <td>
                                            <?php switch ($campaign->status) {
                                                    case CREATED:
                                                        echo '<span class="usagetxt bluetxt">Created</span>';
                                                        break;
                                                    case STARTED:
                                                        echo '<span class="usagetxt greentxt">Started</span>';
                                                        break;
                                                    case PAUSED:
                                                        echo '<span class="usagetxt orangetxt">Paused</span>';
                                                        break;
                                                    case CANCELED:
                                                        echo '<span class="usagetxt redtxt">Canceled</span>';
                                                        break;
                                                    case COMPLETED:
                                                        echo '<span class="usagetxt greytxt">Completed</span>';
                                                        break;
                                            } ?>
                                        </td>
                                        <td>
                                            <a href="#" title=""><img SRC="<?php echo $base_url.$application; ?>/themes/<?php echo $theme; ?>/img/icons/icon_edit.png" alt="Edit" /></a>
                                            <a href="#" title=""><img SRC="<?php echo $base_url.$application; ?>/themes/<?php echo $theme; ?>/img/icons/icon_approve.png" alt="Approve" /></a>
                                            <a href="#" title=""><img SRC="<?php echo $base_url.$application; ?>/themes/<?php echo $theme; ?>/img/icons/icon_unapprove.png" alt="Unapprove" /></a>
                                            <a href="#" title=""><img SRC="<?php echo $base_url.$application; ?>/themes/<?php echo $theme; ?>/img/icons/icon_delete.png" alt="Delete" /></a>
                                        </td>
                                    </tr>
                                    <?php } ?>
                                    <?php } else { ?>
                                    <tr>
                                        <td style="text-align:center;" colspan="4">No campaign found.</td>
                                    </tr>
                                    <?php } ?>

                                </tbody>
                            </table>
                            <div class="extrabottom">

                                <div class="bulkactions">
                                    <input type="button" class="btn" value="New Campaign" onclick="addCampaign()" />
                                </div>
                            </div>
                            <ul class="pagination">
                                    <li class="text">Previous</li>
                                <li class="page"><a href="#" title="">1</a></li>
                                <li><a href="#" title="">2</a></li>
                                <li><a href="#" title="">3</a></li>
                                <li><a href="#" title="">4</a></li>
                                <li class="text"><a href="#" title="">Next</a></li>
                            </ul>
                            <div style="clear: both;"></div>
                        </div>

                    </div>
                </td>
                <td style="width: 250px; padding: 0 0 0 20px; vertical-align: top;" >
                    <div class="contentcontainer">
                        <div class="headings altheading">
                            <h2>Search Box</h2>
                        </div>
                        <div class="contentbox">
                            <input type="text" class="inputbox smallbox" id="name" name="name" />
                                    <input type="text" class="inputbox smallbox" id="url" name="url" />
                                    <select>
                                            <option>Country</option>
                                    </select>
                                    <select>
                                            <option>Status</option>
                                    </select>
                                    <input type="submit" value="Search" class="btn" />
                        </div>
                    </div>    
                </td>
            </tr>
        </table>
        
        <div style="clear:both;"></div>
        
<?php include('footer.php'); ?>